﻿Imports System.Data

Partial Class Register2
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            If txtFullname.Text = "" Then
                Return
            End If
            If Request.QueryString("k") = "existing" Then
                SqlDataSource1.Update()
            Else
                SqlDataSource1.Insert()
            End If
            Response.Redirect("~/default.aspx")
        Catch ex As Exception
            Dim err As New CustomValidator
            err.IsValid = False
            err.ErrorMessage = ex.Message
            Page.Validators.Add(err)
        End Try
    End Sub

    Protected Sub EngrList_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs) Handles EngrList.Selecting

    End Sub

    'Insert = True is Insert method; false is update
    Protected Sub Page_LoadComplete(sender As Object, e As EventArgs) Handles Me.LoadComplete
        Try
            If Request.QueryString("k") <> "existing" Then
                Response.Write("INSERT")
            Else
                Response.Write("UPDATE")
            End If
            Dim dv As DataView = EngrList.Select(DataSourceSelectArguments.Empty)
            txtFullname.Text = dv(0)(0).ToString
            companylst.SelectedValue = dv(0)(1).ToString
            deptlist.SelectedValue = dv(0)(2).ToString
        Catch ex As Exception

        End Try
        
    End Sub
End Class
